/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package aiaudio.database.tables;

import aiaudio.database.Family;
import aiaudio.database.qualifiers.IntQualifier;
import aiaudio.database.qualifiers.LongQualifier;
import java.io.IOException;
import org.apache.hadoop.hbase.client.HTable;
import org.apache.hadoop.hbase.client.Put;
import org.apache.hadoop.hbase.client.Result;
import org.apache.hadoop.hbase.util.Bytes;

/**
 *
 * @author nastya
 */
public class TemporaryTable extends TableStructure {

    private static final LongQualifier COLUMN_COUNT = new LongQualifier("count");
    private static final IntQualifier DUMMY_COLUMN = new IntQualifier("dummy");
    private static final int DUMMY_VALUE = 0;
    private static final Family SINGLE_FAMILY = new Family("d");

    public static void addDummyValue(Put put) {
        TableStructure.addData(put, SINGLE_FAMILY, DUMMY_COLUMN, DUMMY_VALUE);
    }

    public static long getCountValue(Result res) {
        return TableStructure.getValue(res, SINGLE_FAMILY, COLUMN_COUNT);
    }

    public static void decrementCount(HTable tableInstance, byte[] user) throws IOException {
        TableStructure.incrementColumnValue(tableInstance, Bytes.toString(user), SINGLE_FAMILY, COLUMN_COUNT, -1L);
    }

    public static void addCount(Put put, long userToWrite) {
        TableStructure.addData(put, SINGLE_FAMILY, COLUMN_COUNT, userToWrite);
    }

    @Override
    public Family[] getAllFamilies() {
        return new Family[]{SINGLE_FAMILY};
    }
}
